package com.pozu.new_retail.controllers;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pozu.new_retail.dao.base.JsonResult;
import com.pozu.new_retail.service.ActivityService;
import com.pozu.new_retail.utils.CodeConstants;
import com.pozu.new_retail.utils.CodeProperties;

@Controller
public class ActivityController {

	@Autowired
	private ActivityService activityService;
	
	@ResponseBody
	@RequestMapping(value = "/api/activitys/list", method = RequestMethod.GET)
	public Object getActivitys(HttpServletRequest request) throws Exception{
		
		int appId = Integer.parseInt(request.getHeader("appId"));//那个小程序
		
		String title = request.getParameter("title");//活动标题
		
		HashMap<String, Object> hashMap = new HashMap<String, Object>();
		hashMap.put("appId", appId);
		hashMap.put("title", title);
		
		JsonResult jr = new JsonResult();
		jr.respCode = CodeConstants.SUCCESS_CODE;
		jr.respMsg = CodeProperties.getString(CodeConstants.SUCCESS_MSG);
		
		jr.respData = activityService.queryByMap(hashMap);
		
		return jr;		
	}
	
	@ResponseBody
	@RequestMapping(value = "/api/activitys", method = RequestMethod.GET)
	public Object getActivity(HttpServletRequest request) throws Exception{
		
		int activityId = Integer.parseInt(request.getParameter("activityId"));//活动id
		
		JsonResult jr = new JsonResult();
		jr.respCode = CodeConstants.SUCCESS_CODE;
		jr.respMsg = CodeProperties.getString(CodeConstants.SUCCESS_MSG);
		jr.respData = activityService.queryByActivityId(activityId);
		return jr;		
	}

	@ResponseBody
	@RequestMapping(value = "/api/test", method = RequestMethod.GET)
	public Object test(HttpServletRequest request) throws Exception{

		JsonResult jr = new JsonResult();
		jr.respCode = CodeConstants.SUCCESS_CODE;
		jr.respMsg = CodeProperties.getString(CodeConstants.SUCCESS_MSG);
		jr.respData = "success------ok";
		return jr;
	}

}
